package net.andersand.games.yatzy;

/**
 * Every player needs a Turn, which keeps track of how many times he has thrown his dice.
 */
class Turn {
	private static final int THROWS = 3;

	private int completedThrows;
	private Player player;
	private boolean complete;
	// used to prevent dice locking
	private boolean firstRound;

	Turn(Player player) {
		this.completedThrows = 0;
		this.player = player;
		this.complete = false;
		this.firstRound = true;
	}

	/**
	 * Throws the dice and keeps track of number of throws made.
	 */
	void go() {
		firstRound = false;
		complete = false;
		player.getDice().throwDice();
//		System.out
//				.println(player.getName() + " throws " + player.getDice());
		completedThrows++;
		if (completedThrows == THROWS) {
			completedThrows = 0;
			complete = true;
		}
	}

	boolean complete() {
		return complete;
	}
	
	/**
	 * Only true the first round
	 */
	boolean firstRound() {
		return firstRound;
	}

	int getCompletedThrows() {
		return completedThrows;
	}

	Player getPlayer() {
		return player;
	}
}